package com.shu.socket.multicast.multicast;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

/**
 * @author ssm
 * @version V1.0
 * @description:
 * @date 2019/2/20 19:40
 */

public class SocketClient2 {

  public static void main(String[] args) throws IOException {
    InetAddress group = InetAddress.getByName("224.5.6.7");

    MulticastSocket socket = new MulticastSocket(8888);

    socket.joinGroup(group);

    byte[] bytes = new byte[256];
    while (true) {
      DatagramPacket datagramPacket = new DatagramPacket(bytes, bytes.length);
      socket.receive(datagramPacket);//阻塞

      String string = new String(datagramPacket.getData());
      System.out.println("接收到的数据" + string);
    }
  }
}
